var express = require('express'),
  router = express.Router();

router.get('/set', function(req, res, next) {

  req.app.log(req.cookies);
  res.app.log(req.cookies);
  res.app.log(req.cookies.username);
  res.app.log(req.cookies.username2);
  res.app.log(req.cookies.username3);

  // res.cookie('username', 'helloworld', {
  //   // domain: '.example.com', // 有效域名
  //   // path: '/admin', // 作用路径
  //   // expires: new Date(Date.now() + 900000), // 过期时间
  //   // maxAge: 900000, // 生命周期（和上面的 expires 设置一个就可以了，一般就设置这个吧，简单点）
  //   // httpOnly: true, // js无法读写该cookie
  //   // secure: true // 只在 https 下写入浏览器cookie
  // });
  // res.cookie('username2', {hello: 'world'});
  // res.cookie('username3', {hello: 'world', hello: ['hello', 'world']});
  // res.cookie('username4', {hello: 'world', hello: ['hello', {hello2: 'world2'}]});
  // res.cookie('username5', ['hello', 'world']);
  // res.cookie('username6', [{hello: 'world'}, {hello2: 'world2'}]);

  res.status(200);
  res.send('set cookies');

  /*
  浏览器端
  document.cookie
  "username=helloworld; username2=j%3A%7B%22hello%22%3A%22world%22%7D; username3=j%3A%7B%22hello%22%3A%5B%22hello%22%2C%22world%22%5D%7D; username4=j%3A%7B%22hello%22%3A%5B%22hello%22%2C%7B%22hello2%22%3A%22world2%22%7D%5D%7D; username5=j%3A%5B%22hello%22%2C%22world%22%5D; username6=j%3A%5B%7B%22hello%22%3A%22world%22%7D%2C%7B%22hello2%22%3A%22world2%22%7D%5D"\
  decodeURI("%3A%7B%22hello%22%3A%22world%22%7D") => "%3A{"hello"%3A"world"}"
  decodeURIComponent("%3A%7B%22hello%22%3A%22world%22%7D") => ":{"hello":"world"}"

   */
});

router.get('/clear', function(req, res, next) {
  res.clearCookie('username');
  res.status(200);
  res.send('clear cookies');
});

module.exports = router;